/**
 * Created by tsingwong on 16-6-28.
 */
// $.prototype.serializeObject=function(){
//     var a, o, h ,i, e;
//     a = this.serializeArray();
//     o = {}
//     h = o.hasOwnProperty;
//     for(i=0;i<a.length;i++){
//         e = a[i];
//         if (!h.call(o, e.name)){
//             o[e.name] = e.value;
//         }
//     }
//     return o;
// };


function getJson() {
    var $input = $("input");
    var json = {
        paperId:null,
        email: null,
        name: null,
        subject: null,
        summary: [],
        problem: [],
        goal: []
        // product: []
    }

    $.each($input, function (index, item) {
        // console.log($(item).attr('name'));
        // console.log($(item).val());
        var key = $(item).attr('name'),
            value = $(item).val();
        if (json[key] instanceof Array) {
            json[key].push(value);
        } else {
            json[key] = value;
        }
    })
    json.paperId = json.email;
    json = JSON.stringify(json);
    console.log(json);
    return json;
}


$('#submit').click(function () {
    var json = getJson();

    $.ajax({
        type: 'POST',
        dataType: "json",
        url: 'http://192.168.109.29:8080/207Shared/SendOne',
        data: {
            weekPaper: json
        },
        success: function () {
            alert('Success!');
        },
        error: function (err) {
            console.log(err);
        }
    });
})
